package org.groupg.practice.guava;

import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;

public class GuavaStopwatchExample {
    public static void main(String[] args) throws InterruptedException {
        Stopwatch stopwatch = Stopwatch.createStarted();

        // 模拟一些处理（例如，线程休眠1秒）
        Thread.sleep(1234);

        // 停止计时器
        stopwatch.stop();

        // 获取经过的时间并格式化为人类可读的形式
        long elapsedMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
        String humanReadableTime = String.format("%02d:%02d.%03d",
            TimeUnit.MILLISECONDS.toMinutes(elapsedMillis),
            TimeUnit.MILLISECONDS.toSeconds(elapsedMillis) % 60,
            elapsedMillis % 1000);

        // 打印人类可读的时间
        System.out.println("Elapsed Time: " + humanReadableTime);
    }
}